#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# @author: Florian Dorn <florian.dorn@gmail.com>
# @package: gnome-agenda
# @license: GNU GPLv2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import datetime

print datetime.datetime.now()
try:
	import pygtk
	import gtk
	
	v = gtk.pygtk_version
	if( not (v[0] >1 and v[1] > 9)):
		raise Exception()
except:
	import sys
	print "Could not import GTK version (> 2.10)"
	sys.exit(1)

import dbus
import dbus.service
import dbus.glib
import gobject


import logging
LOGGER = logging.getLogger(__name__)


from optparse import OptionParser
from agenda.appointment import *
from agenda.static import APP_VERSION
from agenda.ui.Agenda import Agenda

__author__ = 'florian.dorn@gmail.com (Florian Dorn)'


# Parse commandline options
usage = "gnome-agenda [-p] [-v]"
parser = OptionParser(usage=usage,version="gnome-agenda %s" % APP_VERSION )

parser.add_option("-u", "--update", dest="update", default=False, action="store_true", help="Update Calendars")
parser.set_defaults(preferences=False)


(options, args) = parser.parse_args()



dbus.mainloop.glib.DBusGMainLoop (set_as_default=True)
gobject.threads_init()
bus = dbus.SessionBus ()
request = bus.request_name ("org.domain.GnomeAgenda", dbus.bus.NAME_FLAG_DO_NOT_QUEUE)
if request != dbus.bus.REQUEST_NAME_REPLY_EXISTS:
	init_plugin_system()

	agenda = Agenda (bus, '/', "org.domain.GnomeAgenda")

else:
	object = bus.get_object ("org.domain.GnomeAgenda", "/")
	#agenda only has the proxy methods
	agenda = dbus.Interface (object, "org.domain.GnomeAgenda")
	
agenda.start(options.__dict__)
if agenda.is_running ():
	gtk.gdk.notify_startup_complete ()

